home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / double13 / double13.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-24  |  3.6 KB  |  177 lines

  1. /*
  2.    double13.c
  3.  
  4.    Double buffering in VGA mode 13h (320x200, 256 colors)
  5.  
  6.    Davor Slamnig, 11/94
  7.    (slama@slama.pub.hr)
  8.  
  9.    BC++ 3.1 - small model
  10.  
  11.    VGA is set to "big map" mode.
  12.    The video memory starts at a000h and is 128K long.
  13.    Page 2 begins at b000h. Page 1 one is filled with blue,
  14.    page 2 with red (system colors).
  15.    The program first switches pages using BIOS, then
  16.    does a smooth scroll through the pages using VGA
  17.    registers to change screen start address.
  18.  
  19.    Disclaimer: May not work with your card.
  20. */
  21.  
  22. #include <dos.h>
  23. #include <mem.h>
  24.  
  25. #define VIDEO           0x10                              /* video int  */
  26. #define VGAPTR          ((unsigned char far*)0xa0000000)  /* video base */
  27. #define VGAPTR_2        ((unsigned char far*)0xb0000000)  /* page 2     */
  28.  
  29. typedef struct palette{
  30.    unsigned char R;
  31.    unsigned char G;
  32.    unsigned char B;
  33. }PALETTE;
  34.  
  35. unsigned char far* VGA_screen = VGAPTR;
  36. unsigned char Video_page = 0;
  37.  
  38. PALETTE Syspal[256];
  39. unsigned char Old_video_mode;
  40.  
  41. void set_vmode(unsigned char mode)
  42. {
  43.    union REGS regs;
  44.  
  45.    regs.h.ah = 0;             /* set video mode */
  46.    regs.h.al = mode;
  47.  
  48.    int86(VIDEO, ®s, ®s);
  49. }
  50.  
  51. unsigned char get_vmode(void)
  52. {
  53.    union REGS regs;
  54.  
  55.    regs.h.ah = 0x0f;             /* get video mode */
  56.  
  57.    int86(VIDEO, ®s, ®s);
  58.  
  59.    return regs.h.al;
  60. }
  61.  
  62. void big_map(void)
  63. {                          /* from Kliewer's book */
  64.     outportb(0x3ce, 6);    /* Graphics 1 and 2 Address register,
  65.                            index 6 - Miscellaneous  */
  66.     outportb(0x3cf, 1);    /* graphics mode on, chain off,
  67.                               memory map: a000h/128K */
  68. }
  69.  
  70. void set_vpage(unsigned char video_page)
  71. {
  72.    union REGS regs;
  73.  
  74.    regs.h.ah = 5;                /* set active display page */
  75.    regs.h.al = (video_page);
  76.    int86(VIDEO, ®s, ®s);   /* call BIOS */
  77. }
  78.  
  79. void get_palette(PALETTE *color)
  80. {
  81.    int k;
  82.  
  83.    disable();
  84.  
  85.    for(k = 0; k < 256; ++k, ++color){
  86.       outportb(0x3c7, k);
  87.       color->R = inportb(0x3c9) & 0x3f;
  88.       color->G = inportb(0x3c9) & 0x3f;
  89.       color->B = inportb(0x3c9) & 0x3f;
  90.    }
  91.    enable();
  92. }
  93.  
  94. void set_palette(PALETTE *color)
  95. {
  96.    int k;
  97.  
  98.    disable();
  99.  
  100.    for(k = 0; k < 256; ++k, ++color){
  101.       outportb(0x3c8, k);
  102.       outportb(0x3c9, color->R);
  103.       outportb(0x3c9, color->G);
  104.       outportb(0x3c9, color->B);
  105.    }
  106.    enable();
  107. }
  108.  
  109. void draw_map(void)
  110. {
  111.    _fmemset(VGAPTR, 1, 64000U);
  112.    _fmemset(VGAPTR_2, 4, 64000U);
  113. }
  114.  
  115. void set_startline(int line)
  116. {
  117.    unsigned lline;
  118.  
  119.    lline = (unsigned)line * 80U;
  120.  
  121.    outportb(0x3d4, 0x0c); /* CRTC address (color), Start address high */
  122.    outportb(0x3d5, lline >> 8);     /* hi-byte */
  123.  
  124.    outportb(0x3d4, 0x0d); /* CRTC address (color), Start address low */
  125.    outportb(0x3d5, lline & 0xff);   /* lo-byte */
  126. }
  127.  
  128. void scroll(void)
  129. {
  130.    int line;
  131.  
  132.    for(line = 0; line < 200; ++line){
  133.       set_startline(line);
  134.       delay(10);
  135.    }
  136.  
  137.    for(; line >= 0; --line){
  138.       set_startline(line);
  139.       delay(10);
  140.    }
  141. }
  142.  
  143. main(void)
  144. {
  145.    int k;
  146.  
  147.    Old_video_mode = get_vmode();
  148.    get_palette(Syspal);
  149.    set_vmode(0x13);
  150.    big_map();
  151.    VGA_screen = VGAPTR;
  152.    set_vpage(0);
  153.  
  154.    draw_map();
  155.  
  156.    for(k = 0; k < 7; ++k){
  157.       if(Video_page == 0){
  158.          VGA_screen = VGAPTR_2;
  159.          Video_page = 2;
  160.       }
  161.       else{
  162.          VGA_screen = VGAPTR;
  163.          Video_page = 0;
  164.       }
  165.       set_vpage(Video_page);
  166.       delay(300);
  167.    }
  168.  
  169.    scroll();
  170.  
  171.    set_vmode(Old_video_mode);
  172.    set_palette(Syspal);
  173.  
  174.    return 0;
  175. }
  176.  
  177.